package com.legolas.spring.aspectj;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2016/11/8 0008
 * Time: 10:22
 */
@Component
@Aspect
public class LoggingAspectJ {

    //对addCustomer方法加前置劫持
    @Before("com.legolas.spring.aspectj.PointcutsDefinition.addCustomerLog()")
    public void logBefore(JoinPoint joinPoint){
        System.out.println("logBefore() is running ...");
        System.out.println("hijacked:"+joinPoint.getSignature().getName());
        System.out.println("**********");
    }

    //直接对所有方法劫持。
    @Before("execution(* com.legolas.spring.aspectj.CustomerBoServiceImpl.*())")
    public void logAllBefore(JoinPoint joinPoint){
        System.out.println("logAllBefore() is running ...");
        System.out.println("hijacked:"+joinPoint.getSignature().getName());
        System.out.println("**********");
    }

    //对delete方法加后置劫持
    @After("com.legolas.spring.aspectj.PointcutsDefinition.deleteCustomerLog()")
    public void logAfter(JoinPoint joinPoint){
        System.out.println("logAfter() is running ...");
        System.out.println("hijacked:"+joinPoint.getSignature().getName());
        System.out.println("**********");
    }


}
